﻿namespace WMS6.Web.Analytics
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.AnalyticsReportService2Ref;
    using WMS6.Web.UserControls;

    public class DailyInvPalletRptList : BasePage
    {
        protected Button btnExport;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected Button btnSearch;
        protected HtmlForm F15651;
        protected GridView gvDailyInvPallet;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdnFrom;
        protected Label lblDailyInvPalletList;
        protected Label lblMsg;
        protected Label lblTotalCase;
        protected Label lblTotalCaseText;
        protected Label lblTotalPallet;
        protected Label lblTotalPalletText;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        private decimal totalCase;
        private decimal totalPallet;
        protected UpdatePanel up1;

        private void BindData2DailyInvPalletList(DailyInvPalletRptQueryEntity dailyInvPalletRptQueryEntity)
        {
            this.PagerFooter.CurrentPage = int.Parse(dailyInvPalletRptQueryEntity.CurrentPage);
            DataSet ds = AnalyticsReportService2ClientProxy.GetInstance().GetDailyInvPalletRptDataSet(dailyInvPalletRptQueryEntity);
            this.gvDailyInvPallet.Visible = true;
            if (ds != null)
            {
                base.BindData2GridView(this.gvDailyInvPallet, ds);
                if ((ds != null) && (ds.Tables.Count > 1))
                {
                    this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                    this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
                }
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            DailyInvPalletRptQueryEntity dailyInvPalletRptQueryEntity = this.GetDailyInvPalletQueryEntity();
            dailyInvPalletRptQueryEntity.IsGetAll = true;
            this.hdnActionID.Value = "EXPORT";
            string currentPageIndex = dailyInvPalletRptQueryEntity.CurrentPage;
            dailyInvPalletRptQueryEntity.CurrentPage = "0";
            try
            {
                using (DataSet ds = AnalyticsReportService2ClientProxy.GetInstance().GetDailyInvPalletRptDataSet(dailyInvPalletRptQueryEntity))
                {
                    base.Export2Excel("DailyInvPalletRpt.xls", "15651", this.gvDailyInvPallet, ds);
                }
            }
            finally
            {
                dailyInvPalletRptQueryEntity.IsGetAll = false;
                dailyInvPalletRptQueryEntity.CurrentPage = currentPageIndex;
                this.SetDailyInvPalletQueryEntity(dailyInvPalletRptQueryEntity);
            }
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            DailyInvPalletRptQueryEntity dailyInvPalletRptQueryEntity = this.GetDailyInvPalletQueryEntity();
            dailyInvPalletRptQueryEntity.CurrentPage = "0";
            this.BindData2DailyInvPalletList(dailyInvPalletRptQueryEntity);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            DailyInvPalletRptQueryEntity dailyInvPalletRptQueryEntity = this.GetDailyInvPalletQueryEntity();
            dailyInvPalletRptQueryEntity.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2DailyInvPalletList(dailyInvPalletRptQueryEntity);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            DailyInvPalletRptQueryEntity dailyInvPalletRptQueryEntity = this.GetDailyInvPalletQueryEntity();
            dailyInvPalletRptQueryEntity.OWNER_ID = "";
            dailyInvPalletRptQueryEntity.SKU_ID = "";
            dailyInvPalletRptQueryEntity.StartDateTime = "";
            dailyInvPalletRptQueryEntity.EndDateTime = "";
            this.BindData2DailyInvPalletList(dailyInvPalletRptQueryEntity);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            DailyInvPalletRptQueryEntity dailyInvPalletRptQueryEntity = this.GetDailyInvPalletQueryEntity();
            if (int.Parse(dailyInvPalletRptQueryEntity.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                dailyInvPalletRptQueryEntity.CurrentPage = (int.Parse(dailyInvPalletRptQueryEntity.CurrentPage) + 1).ToString();
                this.BindData2DailyInvPalletList(dailyInvPalletRptQueryEntity);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            DailyInvPalletRptQueryEntity dailyInvPalletRptQueryEntity = this.GetDailyInvPalletQueryEntity();
            if (int.Parse(dailyInvPalletRptQueryEntity.CurrentPage) > 0)
            {
                dailyInvPalletRptQueryEntity.CurrentPage = (int.Parse(dailyInvPalletRptQueryEntity.CurrentPage) - 1).ToString();
                this.BindData2DailyInvPalletList(dailyInvPalletRptQueryEntity);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            DailyInvPalletRptQueryEntity dailyInvPalletRptQueryEntity = this.GetDailyInvPalletQueryEntity();
            this.BindData2DailyInvPalletList(dailyInvPalletRptQueryEntity);
        }

        private DailyInvPalletRptQueryEntity GetDailyInvPalletQueryEntity()
        {
            return (base.PageQueryEntitySession as DailyInvPalletRptQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                DailyInvPalletRptQueryEntity dailyInvPalletRptQueryEntity = this.GetDailyInvPalletQueryEntity();
                dailyInvPalletRptQueryEntity.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2DailyInvPalletList(dailyInvPalletRptQueryEntity);
            }
        }

        protected void gvDailyInvPallet_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F15651", this.gvDailyInvPallet);
        }

        protected void gvDailyInvPallet_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                e.Row.Attributes.Add("ondblclick", "JavaScript:document.getElementById('" + ((CheckBox) e.Row.FindControl("chbSelect")).ClientID + "').click();");
                if ((((Label) e.Row.FindControl("lblCase")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblCase")).Text))
                {
                    this.totalCase += decimal.Parse(((Label) e.Row.FindControl("lblCase")).Text);
                }
                if ((((Label) e.Row.FindControl("lblPallet")) != null) && !string.IsNullOrEmpty(((Label) e.Row.FindControl("lblPallet")).Text))
                {
                    this.totalPallet += decimal.Parse(((Label) e.Row.FindControl("lblPallet")).Text);
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblTotalCaseText.Text = double.Parse(this.totalCase.ToString()).ToString();
                this.lblTotalPalletText.Text = double.Parse(this.totalPallet.ToString()).ToString();
            }
        }

        protected void gvDailyInvPallet_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                DailyInvPalletRptQueryEntity dailyInvPalletRptQueryEntity = this.GetDailyInvPalletQueryEntity();
                dailyInvPalletRptQueryEntity.SortField = e.SortExpression;
                if (dailyInvPalletRptQueryEntity.SortDirection == "ASC")
                {
                    dailyInvPalletRptQueryEntity.SortDirection = "DESC";
                }
                else if (dailyInvPalletRptQueryEntity.SortDirection == "DESC")
                {
                    dailyInvPalletRptQueryEntity.SortDirection = "ASC";
                }
                this.BindData2DailyInvPalletList(dailyInvPalletRptQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            DailyInvPalletRptQueryEntity dailyInvPalletRptQueryEntity = new DailyInvPalletRptQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    dailyInvPalletRptQueryEntity.OWNER_ID = this.PreviousPage.OwnerID;
                    dailyInvPalletRptQueryEntity.SKU_ID = this.PreviousPage.SkuID;
                    dailyInvPalletRptQueryEntity.StartDateTime = this.PreviousPage.StartDate;
                    dailyInvPalletRptQueryEntity.EndDateTime = this.PreviousPage.EndDate;
                }
                else
                {
                    dailyInvPalletRptQueryEntity.OWNER_ID = "";
                    dailyInvPalletRptQueryEntity.SKU_ID = "";
                    dailyInvPalletRptQueryEntity.StartDateTime = "";
                    dailyInvPalletRptQueryEntity.EndDateTime = "";
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            dailyInvPalletRptQueryEntity.IsGetAll = false;
            dailyInvPalletRptQueryEntity.CurrentPage = "0";
            dailyInvPalletRptQueryEntity.PageSize = this.gvDailyInvPallet.PageSize.ToString();
            dailyInvPalletRptQueryEntity.SortField = " DAYDATE,OWNER_ID,SKU_ID";
            dailyInvPalletRptQueryEntity.SortDirection = "ASC";
            this.PagerFooter.PageSize = this.gvDailyInvPallet.PageSize;
            this.SetDailyInvPalletQueryEntity(dailyInvPalletRptQueryEntity);
            this.BindData2DailyInvPalletList(dailyInvPalletRptQueryEntity);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                base.InitAnalyticsReportGridview(this.gvDailyInvPallet);
                this.LoadData();
            }
        }

        private void SetDailyInvPalletQueryEntity(DailyInvPalletRptQueryEntity dailyInvPalletRptQueryEntity)
        {
            base.PageQueryEntitySession = dailyInvPalletRptQueryEntity;
        }

        public DailyInvPalletRptQuery PreviousPage
        {
            get
            {
                return (DailyInvPalletRptQuery) base.PreviousPage;
            }
        }
    }
}

